//
//  SMMenuListTableViewCell.m
//  SaveMoney
//
//  Created by user on 2018/11/22.
//  Copyright © 2018年 Sunflower. All rights reserved.
//

#import "SMMenuListTableViewCell.h"

#import "SMMunuItemCollectionViewCell.h"
#import "AdaptiveHeader.h"
#import "SMSaveMoneyView.h"
#import "SMMessageListViewController.h"

@interface SMMenuListTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property (nonatomic, copy) NSArray *listArray;

@end

@implementation SMMenuListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    self.listArray = @[@{@"image":@"money_zhichu", @"title":@"支出"},
                       @{@"image":@"saveInmoney", @"title":@"存入"},
                       @{@"image":@"saveList", @"title":@"记录"}];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return  3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SMMunuItemCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SMMunuItemCollectionViewCell" forIndexPath:indexPath];
    NSDictionary *dic = _listArray[indexPath.row];
    cell.image.image = [UIImage imageNamed:dic[@"image"]];
    cell.titleLabel.text = dic[@"title"];
    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake((SBIPHONEWIDTH-SBScaleNumber(60))/3, SBIPHONEHEIGHT/8);
}


- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(SBScaleNumber(10), SBScaleNumber(0), SBScaleNumber(10), SBScaleNumber(0));
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
   
    __weak typeof(self) weakSelf = self;
    
//    if (indexPath.row == 0) {
//        
//        SMSaveMoneyView *view = [SMSaveMoneyView showView];
//        
//        view.block = ^(UIButton * _Nonnull sender, NSInteger money, NSString * _Nonnull message) {
//            
//            weakSelf.moneyModel.alreadyMoney -= money;
//            [weakSelf.moneyModel update];
//            
//            SMSaveMoneyMessageModel *model = [[SMSaveMoneyMessageModel alloc] init];
//            model.projectId = weakSelf.moneyModel.id;
//            model.userKey = weakSelf.moneyModel.userKey;
//            model.total = weakSelf.moneyModel.totalMoney;
//            model.bitMoney = weakSelf.moneyModel.totalMoney - weakSelf.moneyModel.alreadyMoney;
//            model.saveMoney = 0;
//            model.message = message;
//            model.type = CostMoney;
//            model.costMoney = money;
//            model.creationTime = [NSString getNowTime];
//            [model save];
//        };
//        
//    } else if (indexPath.row == 1) {
//        
//        SMSaveMoneyView *view = [SMSaveMoneyView showView];
//        
//        view.block = ^(UIButton * _Nonnull sender, NSInteger money, NSString * _Nonnull message) {
//            
//            weakSelf.moneyModel.alreadyMoney += money;
//            [weakSelf.moneyModel update];
//            
//            SMSaveMoneyMessageModel *model = [[SMSaveMoneyMessageModel alloc] init];
//            model.projectId = weakSelf.moneyModel.id;
//            model.userKey = weakSelf.moneyModel.userKey;
//            model.total = weakSelf.moneyModel.totalMoney;
//            model.bitMoney = weakSelf.moneyModel.alreadyMoney;
//            model.saveMoney = money;
//            model.message = message;
//            model.type = SaveMoney;
//            model.costMoney = 0;
//            model.creationTime = [NSString getNowTime];
//            [model save];
//        };
//    } else {
//        
//        
//        
//    }
    
    if (self.block) {
        self.block(indexPath, [collectionView cellForItemAtIndexPath:indexPath]);
    }
}


@end
